package com.yunji.storage.context;

import com.yunji.base.enums.SystemName;
import com.yunji.common.constant.LogicCode;
import com.yunji.common.enums.business.StorageStatus;
import com.yunji.common.enums.business.StorageType;
import com.yunji.common.exception.ServiceException;
import com.yunji.common.utils.TimeUtils;
import com.yunji.common.utils.uuid.UUIDUtils;
import com.yunji.order.domain.OrderDO;
import com.yunji.storage.domain.StorageTicketDO;
import com.yunji.storage.enums.DeletableStatus;
import com.yunji.storage.enums.StorageBusinessType;

public class StorageTicketBuilder {

    private final StorageTicketDO storageTicketDO;

    private StorageTicketBuilder() {
        this.storageTicketDO = new StorageTicketDO();
    }

    public static StorageTicketBuilder builder() {
        return new StorageTicketBuilder();
    }


    public StorageTicketBuilder buildOrder(OrderDO orderDO) {
        ServiceException.throwException(orderDO == null, "订单为空");
        storageTicketDO.setBusinessId(orderDO.getOrderId());
        storageTicketDO.setBusinessCode(orderDO.getOrderCode());
        storageTicketDO.setBusinessType(StorageBusinessType.SALES_BUSINESS.getCode());
        storageTicketDO.setStorageType(StorageType.OUT_STORAGE.getCode());
        storageTicketDO.setDeletable(DeletableStatus.CAN_NOT.getCode());
        storageTicketDO.setTicketCode(UUIDUtils.outStorageCode());
        storageTicketDO.setOperateTime(TimeUtils.getNowDate());
        storageTicketDO.setOperateName(SystemName.ENABLED.getText());
        storageTicketDO.setStorageStatus(StorageStatus.WAIT_STORAGE.getCode());
        storageTicketDO.setUseStatus(LogicCode.YES);
        storageTicketDO.setBelongId(orderDO.getBelongId());
        return this;
    }

    public StorageTicketDO build() {
        return this.storageTicketDO;
    }
}
